local vouncherId = ARGV[1]
local userId = ARGV[2]
local stockKey = 'seckill:stock:' .. vouncherId
local orderKey = 'seckill:order' .. vouncherId

-- 判断库存是否充足
if (tonumber(redis.call('get', stockKey)) <= 0) then
    return 1
end
-- 判断是否已经下单了
if (redis.call('sismember', orderKey, userId) == 1) then
	return 2
end
-- 扣减库存
redis.call('incrby', stockKey, -1)
redis.call('sadd', orderKey, userId)
return 0